package cn.caskm.souvenirshopsystem.controller.admin;

import cn.caskm.souvenirshopsystem.domain.Result;
import cn.caskm.souvenirshopsystem.domain.dto.PageDTO;
import cn.caskm.souvenirshopsystem.domain.po.Coupon;
import cn.caskm.souvenirshopsystem.domain.query.CouponQuery;
import cn.caskm.souvenirshopsystem.domain.query.UserCouponQuery;
import cn.caskm.souvenirshopsystem.domain.vo.CouponVO;
import cn.caskm.souvenirshopsystem.domain.vo.UserCouponVO;
import cn.caskm.souvenirshopsystem.service.CouponService;
import cn.caskm.souvenirshopsystem.service.UserCouponService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/coupon")
@RequiredArgsConstructor
public class AdminCouponController {

    private final CouponService couponService;
    private final UserCouponService userCouponService;

    @GetMapping("/page")
    public Result<PageDTO<CouponVO>> page(CouponQuery query) {
        return couponService.page(query);
    }

    @PostMapping("/create")
    public Result<Void> createCoupon(@RequestBody Coupon coupon) {
        return couponService.createCoupon(coupon);
    }

    @PutMapping("/update")
    public Result<Void> updateCoupon(@RequestBody Coupon coupon) {
        return couponService.updateCoupon(coupon);
    }

    @DeleteMapping("/{couponId}")
    public Result<Void> deleteCoupon(@PathVariable("couponId") Integer couponId) {
        return couponService.deleteCoupon(couponId);
    }

    @PutMapping("/updateStatus/{couponId}")
    public Result<Void> updateStatus(@PathVariable("couponId") Integer couponId,
                                   @RequestParam("status") String status) {
        return couponService.updateStatus(couponId, status);
    }

    @GetMapping("/userCoupons")
    public Result<PageDTO<UserCouponVO>> getUserCoupons(UserCouponQuery query) {
        return userCouponService.page(query);
    }

}
